//
//  CYasyn2syn.m
//  CYasyn2syn
//
//  Created by baidu on 7/7/16.
//  Copyright © 2016 caoyuan. All rights reserved.
//

#import "CYasyn2syn.h"

@implementation CYasyn2syn

@end
id CAOYUAN_ASYN_TO_SYN(DoYourTaskBlock yourTaskBlock) {
    __block id result = nil;
    ReturnBlock returnBlock = ^(id str){
        result = str;
    };
    yourTaskBlock(returnBlock);
    while (result == nil) {
        [NSThread sleepForTimeInterval:0.1];
    }
    return result;
}

id CAOYUAN_ASYN_TO_SYN_WITH_OUTTIME_DEFAULT_VALUE(DoYourTaskBlock yourTaskBlock, NSTimeInterval outTime, id defaultValue) {
    __block id result = nil;
    NSTimeInterval timeCount = 0;
    ReturnBlock returnBlock = ^(id str){
        result = str;
    };
    yourTaskBlock(returnBlock);
    while (result == nil && timeCount < outTime*10) {
        [NSThread sleepForTimeInterval:0.1];
        timeCount++;
    }
    if (result != nil) {
        return result;
    }
    return defaultValue;
}
